package com.mec.web.y2013.headfirstservlet;

import java.io.IOException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebInitParam;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.mec.beans.y2013.headfirstservlet.BeerExpert;

/**
 * Servlet implementation class Ch2SelectBeer
 */
@WebServlet(
	urlPatterns = {"/2013/03_Mar/SelectBeer.action"}
	,initParams={@WebInitParam(name = "jspDest", // jspDest: the jsp page this servlet jumps forward to; 
			value = "/WEB-INF/2013/jsp/03_Mar/hfs/Ch2_BeerResult.jsp")}
	)
public class Ch2SelectBeerServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public Ch2SelectBeerServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		String beerColor = request.getParameter("color");
		List<String> brandsList = BeerExpert.getInstance().getBrands(beerColor);
		request.setAttribute("brands", brandsList);
		
		String path = getInitParameter("jspDest");
		//String path = "/WEB-INF/2013/jsp/03_Mar/hfs/Ch2_BeerResult.jsp";//destination jsp page;
		request.getRequestDispatcher(path).forward(request, response);
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		doGet(request, response);
	}

}
